package com.mango.leet.code.middle;

import java.util.*;

/**
 * @Author: mango
 * @Date: 2024/3/23 23:47
 */
public class LC46 {
    List<List<Integer>> resultList = new ArrayList<>();
    LinkedList<Integer> trackList = new LinkedList<>();
    public List<List<Integer>> permute(int[] nums) {
        trackback(nums, nums.length);
        return resultList;
    }

    private void trackback(int[] nums, int size) {
        if (trackList.size() == size) {
            resultList.add(new ArrayList<>(trackList));
            return ;
        }
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            if (!trackList.contains(num)) {
                trackList.addLast(num);
                trackback(nums, size);
                trackList.removeLast();
            }
        }
    }

    public static void main(String[] args) {
        LC46 r = new LC46();
        //System.out.println(r.permute(new int[]{1,2,3}));
        System.out.println(r.permute(new int[]{1,1,2}));
    }
}
